local ceil = math.ceil

function insert(barrels, time, value)
	local index  = ceil(time/barrels.interval)
	if index==0 then index=1 end
	
	if index>barrels.size then index = barrels.size end
	index = (index + barrels.offset) % barrels.size
	if index==0 then index = barrels.size end
	
	local barrel = barrels[index]
	local len	 = barrel[0]+1
	barrel[len]	 = value
	barrel[0]	 = len
end


function init(interval,size)
	local barrels = {interval=interval, size=size, offset=0, insert=insert}
	
	for i=1,size do
		barrels[i] = {[0]=0}
	end

	return barrels
end